package com.ljy.my_study.文件操作;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

/** 
* @author James
* @date 2018年9月7日 
*/
public class TestMain2 {
	public static void main(String[] args) throws IOException {
		String path="C:\\Users\\hasee\\Desktop\\sub\\表二字段.txt";
		BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(path)));
		StringBuilder sb=new StringBuilder();
		String line=null;
		while((line=br.readLine())!=null) {
//			System.out.println(line);
			String[] lineArr=line.split("(\\t){1}");
//			if(lineArr.length>1) {
//				sb.append(""+lineArr[0].trim()+",");
//			}else {
//				sb.append("null as "+line.trim()+",");
//			}
			if(lineArr[3].contains("留用")) {
				if(lineArr[2].contains("NOT NULL")&&
						(lineArr[1].contains("Bit")
						||lineArr[1].contains("numeric")
						||lineArr[1].contains("money")
						||lineArr[1].contains("float")
						||lineArr[1].contains("bigint")
						)
						) {
					sb.append("'0' as "+lineArr[0].trim()+",");
				}else if(lineArr[2].contains("NOT NULL")&&
						(
								lineArr[1].contains("nvarchar")	
								)) {
					sb.append("'' as "+lineArr[0].trim()+",");
				}else {
					sb.append("'' as "+lineArr[0].trim()+",");
				}
			}else {
				if(lineArr[2].contains("NOT NULL")&&
						(lineArr[1].contains("Bit")
						||lineArr[1].contains("numeric")
						||lineArr[1].contains("money")
						||lineArr[1].contains("float")
						||lineArr[1].contains("bigint")
						)
						) {
					sb.append("(case when "+lineArr[0].trim()+" is null then '0' else "+lineArr[0].trim()+" end) as "+lineArr[0].trim()+",");
				}else if(lineArr[2].contains("NOT NULL")&&
						(
								lineArr[1].contains("nvarchar")	
								)) {
					sb.append("(case when "+lineArr[0].trim()+" is null then '' else "+lineArr[0].trim()+" end) as "+lineArr[0].trim()+",");
				}else if(lineArr[2].contains("NOT NULL")){
					sb.append("(case when "+lineArr[0].trim()+" is null then '' else "+lineArr[0].trim()+" end) as "+lineArr[0].trim()+",");
				}else {
					sb.append(""+lineArr[0].trim()+",");
				}
			}
			
			System.out.println("--"+lineArr.length+"--"+lineArr[0]+"--"+lineArr[1]+"--"+lineArr[2]+"--"+lineArr[3]);
		}
		System.out.println("-------------------");
		System.out.println(sb.toString());
	}
}
